//
//  SCViewManager.m
//  Products_B
//
//  Created by lanou on 16/5/29.
//  Copyright © 2016年 朋学友. All rights reserved.
//

#import "SCViewManager.h"
#import <UIKit/UIKit.h>
@interface SCViewManager ()<UIScrollViewDelegate>

@property (nonatomic ,strong)UIScrollView *scrollView;

@property (nonatomic, strong)UIPageControl *page;

@property (nonatomic, strong)NSArray *picArray;

@property (nonatomic, assign)CGRect frame;
@property (nonatomic, assign)NSInteger number;
@end

@implementation SCViewManager
-(void)viewRepeatScrollWithPicArray:(NSArray *)picArray view:(UIView *)view frame:(CGRect)frame withImageViewFrame:(CGRect)imageViewFrame{

    self.picArray = picArray;
    self.frame = frame;
    self.number = 1;
    self.scrollView = [[UIScrollView alloc]initWithFrame:frame];
    _scrollView.delegate = self;
    
    
    _scrollView.contentSize = CGSizeMake(imageViewFrame.size.width * picArray.count, frame.size.height);
    // 改变偏移量 一上来显示 实际上是第二张图
    _scrollView.contentOffset = CGPointMake(0, 0);
    _scrollView.pagingEnabled = YES;
    _scrollView.bounces = NO;
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    
    [view addSubview:_scrollView];
    
    
    for (int i = 0; i < picArray.count; i++) {
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(imageViewFrame.size.width * i, 0,imageViewFrame.size.width, imageViewFrame.size.height)];
        imageView.userInteractionEnabled = YES;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
        
        imageView.tag  = 100 + i;
        
        [imageView addGestureRecognizer:tap];
        [imageView sd_setImageWithURL:[NSURL URLWithString:picArray[i]] placeholderImage:nil completed:nil];
        [_scrollView addSubview:imageView];
        
    }
}

-(void)tapAction:(UITapGestureRecognizer *)tap{
    
    NSLog(@"点击了轻拍手势");
    
    int index = (int)tap.view.tag - 100;
    self.block(index);
}
@end
